#!/usr/bin/python3

import os
import api


def main():
    api.startTool()
    while True:
        cmd = input("AutoGen# ").strip()
        if not cmd:
            continue

        if cmd.find("quit") == 0:
            if cmd != "quit":
                print("Invalid input.")
                continue
            print("")
            print("automatic tool exit.")
            break
        elif cmd.find("show") == 0:
            if cmd != "show":
                print("Invalid input.")
                continue
            os.chdir(".autoedit")
            api.showDatabase(1)
            os.chdir("..")
        elif cmd.find("?") == 0:
            if cmd != "?":
                print("Invalid input.")
                continue
            os.chdir(".autoedit")
            api.showDatabase(0)
            os.chdir("..")
        elif cmd.find("new") == 0:
            words = cmd.split()
            count = len(words)
            if count != 2:
                print("Invalid input.")
                continue
            api.createModule(words[1])
        elif cmd.find("not") == 0:
            words = cmd.split()
            count = len(words)
            if count != 2:
                print("Invalid input.")
                continue
            api.cancelModule(words[1])
        elif cmd.find("rm") == 0:
            words = cmd.split()
            count = len(words)
            if count != 2:
                print("Invalid input.")
                continue
            api.removeModule(words[1])


if __name__ == '__main__':
    main()



